home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-05-15 | 2.1 KB | 75 lines | [TEXT/MPS ] |
- ;
- ; PatchAgent.a
- ;
- ; Universal patch glue for PatchWorks. MPW Assembler version.
- ;
- ; by Patrick C. Beard & Mouse Herrel.
- ;
- ;
- INCLUDE 'Traps.a'
- INCLUDE 'Patch.a' ; bring in record definitions.
- ;
- STRING ASIS
- ;
- FP EQU a6
- ;
- ; PatchAgent
- ;
- ; This routine is meant to be called from a small stub of code that has
- ; this C structure:
- ;
- ;
- ; struct PatchStub {
- ; short jsr_jmp; // absolute jsr/jmp instruction.
- ; long address; // points to the glue code.
- ; Patch* instance; // pointer to instance.
- ; };
- ;
- ; This allows the patch agent code to pull out the instance by the return address
- ; and reduce the size of the per patch overhead.
- ;
- PatchAgent PROC EXPORT
- WITH Patch ; use the Patch object.
- link FP, #0
- movem.l d0-d2/a0-a1/a4-a5, -(sp) ; save the registers.
- move.l 4(FP), a0 ; return address points into PatchStub
- move.l (a0), a0 ; get pointer to Patch out of it.
- move.l itsOld(a0), 4(FP) ; put old trap address on stack.
- move.l itsBehavior(a0), d0 ; get the behavior.
-
- clr.l -(sp) ; save room for stack adjustment.
- move.l a0, -(sp) ; pass Patch instance.
-
- move.l itsGlobals(a0), GLOBALS ; set up the patch's globals.
- move.l d0, a0
- jsr (a0) ; call the behavior.
-
- add.l #4, sp ; remove patch parameter we pushed.
- move.l (sp)+, d0 ; see if we're
- beq.s @restore
-
- ; we're heading off the patch, return to caller.
- ; this is accomplished by copying the return address back before where the
- ; parameters are, and adjusting the frame pointer to remove the caller's
- ; arguments if there are any.
- ;
- ; note, the 36 & 28 are hard coded offsets to the link & return addresses.
- ; They are derived from the PatchFrame structure in Patch.h.
- ; in the case of exceptions, the caller is at 38 because of the status value.
- ; therefore, we can't really tail patch exceptions with this glue.
-
- move.l d0, FP
- move.l 36(sp), -(FP) ; get caller's return address.
- move.l 28(sp), -(FP) ; get old value of FP so unlk works.
-
- @restore
- movem.l (sp)+, d0-d2/a0-a1/a4-a5
- unlk FP
- rts
-
- @macsbug
- dc.b $80 + $A, 'PatchAgent' ; macsbug symbol.
-
- ENDP
- ;
-